#! /bin/bash
awk_version=`gawk 'BEGIN{v=PROCINFO["version"];gsub(/\..*/,"",v);print v}'`
[ $awk_version -lt 4 ] && echo -e "gawk version should be 4.0 or higher\n install it first" && exit 1

awk_path=`which awk`
install_path=`pwd`/src/

sed -i '1 s:^.*$:#! '$awk_path' -f :' src/EMTO
sed -i '/@include/ s:\".*\(toolkit_emto.awk\):\"'$install_path'\1:' src/EMTO
sed -i '/cfgPath=/ s:\".*\(atom.cfg\):\"'$install_path'\1:' src/EMTO
sed -i '/@include/ s:\".*\(function\.awk\):\"'$install_path'\1:' src/toolkit_emto.awk

chmod +x src/EMTO
chmod +x clean.sh
rm -f src/getLAT

ifort -static -o src/getLAT src/getLAT.f
[ -L ~/bin/${1:-"EMTO"} ] && echo -e "${1:-"EMTO"} is exist!\n`ls -l ~/bin/${1:-"EMTO"}`\n you can use:\n'ln -s `pwd`/src/EMTO ~/bin/WhatNameYouWant' to finish install"  || ln -s `pwd`/src/EMTO ~/bin/${1:-"EMTO"} 
